package com.woniuxy.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Map;

/**
 * 分装获取用户信息的类
 */
public class UserContext {
    public static Long getUserId() throws ParseException {
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes()))
                .getRequest();
        String headerJWT = request.getHeader("authorization");
        Map userMap = JWTUtil.getUserMap(headerJWT);
        return (Long) userMap.get("id");
    }
}
